android 5 通知栏

1

今天讲点简单的哦,再日后补坑,通知栏信息;
用Android的人,都应该知道通知栏是个什么东西,下拉会出来一些设置菜单,
当有新的消息时,就会跑到这里,或者比如云音乐,后台听歌,也会有这么一个通知栏信息;
今天就简单的说一下,以后再完善;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,new Intent(this, Photogallery_activity.class),0); //某个intent
Notification notification = new NotificationCompat.Builder(this) //通知对象的创建
.setTicker(resources.getString(R.string.new_picture_title))//信息在通知栏滚动的text,就像新短信会在未下拉的状态来滚动信息
.setSmallIcon(android.R.drawable.ic_menu_report_image)//图标
.setContentTitle(resources.getString(R.string.new_picture_title))//标题
.setContentText(resources.getString(R.string.new_picture_text))//文本
.setContentIntent(pendingIntent)//点击后启动的intent
.setAutoCancel(true)//点击后自动取消,比如云音乐,你点击后,就跳到主页面,不删除通知栏
.build();
NotificationManager notificationManager =(NotificationManager)getSystemService(NOTIFICATION_SERVICE); //创建manager
notificationManager.notify(0,notification);//发送消息

ok,我们就在通知栏建立了我们自己的信息;